import 'package:xbaistack/router.dart';
import 'package:xbaistack/widget/my_button.dart';
import 'package:flutter/material.dart';

class User {
  final int id;
  final String? username;
  User({required this.id, this.username});
  User.idOf(int id)
    : this(id: id, username: null); // 这是一个命名的构造函数，this 重定向到主构造函数
}

class DemoPage extends StatefulWidget with RouterBridge<User> {
  const DemoPage({super.key});

  @override
  State<DemoPage> createState() => _DemoPageState();
}

class _DemoPageState extends State<DemoPage> {
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      final user = widget.argumentOf(context);
      print(user?.id);
      print(user?.username);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Demo')),
      body: Column(
        children: [
          Container(child: Text('demo')),
          MyButtons(
            text: '返回',
            onTap: () async {
              Navigator.pop(context, '这是返回的参数');
            },
          ),
        ],
      ),
    );
  }
}
